package com.zhangfuxing.datatools.core;

import java.io.IOException;

/**
 * @author 张福兴
 * @version 1.0
 * @date 2024/10/2
 * @email zhangfuxing1010@163.com
 */
public class SysUtil {

    public static String getOS() {
        return System.getProperty("os.name").toLowerCase();
    }

    public static boolean isWindows() {
        return getOS().contains("win");
    }

    public static boolean isMac() {
        return getOS().contains("mac");
    }

    public static boolean isUnix() {
        return getOS().contains("nix");
    }

    public static boolean isSolaris() {
        return getOS().contains("sunos");
    }

    public static boolean isLinux() {
        return getOS().contains("linux");
    }

    public static boolean isFreeBSD() {
        return getOS().contains("freebsd");
    }

    public static void clear() {
        ProcessBuilder processBuilder;
        if (isWindows()) {
            processBuilder = new ProcessBuilder("cmd", "/c", "cls");
        } else if (isLinux()) {
            processBuilder = new ProcessBuilder("bash", "clear");
        } else {
            return;
        }
        try {
            processBuilder.inheritIO().start();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}
